<template>
	<view class="">
		<view class="title">
			<alltitleVue :title="title" :url="url" />
		</view>
		<view class="">
			<view class="container-box" v-if="caseList.length>0">
				<view class="info-card" v-for="(item,index) in caseList" :key="index" @click="cardClick(item,index)">
					<view class="card">
						<view class="card-left">
							<view class="">
								{{ getFormattedAddress(item.shippingAddress, item.address) }}
							</view>
							<view class="info">
								<text class="jia" v-if="item.label">{{item.label}}</text>
								<text class="info-name">{{item.name}}</text>
								<text>{{item.mobile}}</text>
							</view>
						</view>
						<image @click.stop="edit(item,index)" class="card-right" :src="addreeImg"
							mode=""></image>
					</view>

				</view>
			</view>
			<view class="empty" v-else>
				<u-empty text="请添加地址" mode="list"></u-empty>
			</view>
		</view>
		<view class="" @click="addressPay">
			<allBtnVue :btnText="addressText" />
		</view>
	</view>

</template>

<script>
	import config from '../../utils/config';
	import {
		addAddress,
		address
	} from '../../service/api.js'
	export default {
		data() {
			return {
				title: "地址管理",
				addressText: "添加地址",
				caseList: [],
				addreeImg: config.topHost + '2024/12/28/f57dee0d71604a9dbcd9575b12ab0871.png',
				select: false
			}
		},
		onLoad(options) {
			if (options.select) {
				this.select = options.select
			}
			this.getaddress();
		},
		onShow() {
			this.getaddress();
		},
		methods: {
			getFormattedAddress(shippingAddress, address) {
				// 在这里可以进行格式化，例如去除多余的空格或进行连接
				return `${shippingAddress}  ${address}`;
			},
			async getaddress() {
				let res = await address();
				if (res.code == 200) {
					this.caseList = res.data.records;
				}
			},
			cardClick(item, index) {
				if (this.select) {
					uni.navigateTo({
						url: `/integration/carOrder/index?addressInfo=${JSON.stringify(item)}&isaddress=true`
					})
				} else {
					uni.navigateTo({
						url: `/My/editAddress/index?item=${JSON.stringify(item)}&title=编辑地址`
					})
				}

			},
			//跳转新增地址
			addressPay() {
				uni.navigateTo({
					url: '/My/addAddress/index'
				})

			},

			//跳转修改地址
			edit(item, index) {
				uni.navigateTo({
					url: `/My/editAddress/index?item=${JSON.stringify(item)}&title=编辑地址`
				})
			},
		},
	}
</script>

<style lang="scss" scoped>
	.title {
		background: #fff;
	}

	.empty {
		height: calc(100vh - 400rpx);
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.container-box {
		padding: 24rpx;

		.info-card {
			margin-top: 24rpx;
			border-radius: 8rpx 8rpx 8rpx 8rpx;
			// border: 1rpx solid #CCA566;
			background: #fff;
			padding: 24rpx;

			.checkbox {
				border-radius: 50%;
				width: 30rpx;
				height: 30rpx;
				margin-right: 8rpx;

				border: 1rpx solid #B3B3B3;
			}

			.selected {
				background: #CCA566;
				border: none;

			}

			.check-box {
				margin-top: 24rpx;
				font-size: 24rpx;
				color: #4D4D4D;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.check-left {
					display: flex;
					justify-content: space-between;
					align-items: center;
				}

				.del-btn {
					width: 80rpx;
					height: 40rpx;
					background: #E6E6E6;
					border-radius: 4rpx 4rpx 4rpx 4rpx;
					line-height: 40rpx;
					text-align: center;

				}
			}

			.card {


				display: flex;
				justify-content: space-between;
				align-items: center;

				.card-left {
					font-size: 24rpx;

					.info {
						margin-top: 24rpx;
						color: #808080;
						.info-name{
							margin-right: 15rpx;
						}
					}

					.jia {
						padding: 0rpx 10rpx;
						margin-right: 10rpx;
						background: #CCA566;
						border-radius: 4rpx 4rpx 4rpx 4rpx;
					}
				}

				.card-right {
					width: 32rpx;
					height: 32rpx;
				}
			}

		}
	}
</style>